package com.dfe.backend.dto;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.sql.Timestamp;

/**
 * 通用参数
 *
 * @author LiChang(lclicht @ qq.com)
 * @version 1.0
 * @class BaseDTO
 * @since 2023-10-30 17:12
 */
@Data
public class BaseDTO {

    /**
     * 分页判定，true-分页，false-不分页
     */
    private Boolean isPage;

    private Integer currentPage;

    private Integer pageSize;

    private Integer startIndex;

    private Integer endIndex;

    private Timestamp startTime;

    private Timestamp endTime;

    /**
     * 根据指定字段排序，驼峰格式
     */
    private String orderByColumn;

    /**
     * 排序，true-升序，false-降序
     */
    private Boolean isAsc;

    public boolean isPage() {
        if (isPage != null) {
            return isPage;
        } else {
            return true;
        }
    }

    public int getCurrentPage() {
        if (NumberUtil.isValidNumber(currentPage)) {
            return currentPage;
        } else {
            return 1;
        }
    }

    public int getPageSize() {
        if (NumberUtil.isValidNumber(pageSize)) {
            return pageSize;
        } else {
            return 10;
        }
    }

    public String getOrderBy() {
        if (StrUtil.isEmpty(orderByColumn)) {
            return "";
        }
        if (isAsc != null) {
            if (!isAsc) {
                return StrUtil.toUnderlineCase(orderByColumn) + " desc";
            }
        }
        return StrUtil.toUnderlineCase(orderByColumn) + " asc";
    }


}
